package com.mail.server.controller;


import com.mail.model.db.SmsHomeRecommendProduct;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.SmsHomeRecommendProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 人气推荐商品表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/home/recommendProduct")
public class SmsHomeRecommendProductController {

    @Autowired
    private SmsHomeRecommendProductService smsHomeRecommendProductService;

    @PostMapping("/create")
    public R<String> addRecommendProduct(@RequestBody List<SmsHomeRecommendProduct> recommendProductsList){
        smsHomeRecommendProductService.addRecommendProduct(recommendProductsList);
        return R.success("");
    }

    @PostMapping("/delete")
    public R<String> deleteRecommendProduct(@RequestParam("ids") List<Long> ids){
        smsHomeRecommendProductService.deleteRecommendProduct(ids);
        return R.success("");
    }

    @GetMapping("/list")
    public R<PageResult> getRecommendProductByPage(@RequestParam(defaultValue = "1") Long pageNum,
                                               @RequestParam(defaultValue = "10") Long pageSize,
                                               String productName,
                                               Integer recommendStatus){
        PageResult page = smsHomeRecommendProductService.getRecommendProductByPage(pageNum,pageSize,productName,recommendStatus);
        return R.success(page);
    }

    @PostMapping("/update/recommendStatus")
    public R<String> updateRecommendProduct(@RequestParam("ids") List<Long> ids,@RequestParam("recommendStatus") Integer recommendStatus){
        smsHomeRecommendProductService.updateRecommendProduct(ids,recommendStatus);
        return R.success("");
    }

    @PostMapping("/update/sort/{id}")
    public R<String> updateSortRecommendProduct(@PathVariable("id") Long id,@RequestParam(required = false) Integer sort){
        smsHomeRecommendProductService.updateSortRecommendProduct(id,sort);
        return R.success("");
    }
}
